package com.kujie.access.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kujie.access.domain.po.AccessPolicySubmitInformation;
import com.kujie.access.domain.po.AccessTenantManagement;
import com.kujie.access.domain.query.PolicySubmitInformationQuery;
import com.kujie.access.domain.vo.EnterpriseRentalInformationVO;
import com.kujie.access.domain.vo.PolicySubmitInformationExportImportVO;
import com.kujie.access.domain.vo.PolicySubmitInformationVO;
import com.kujie.access.mapper.AccessPolicySubmitInformationMapper;
import com.kujie.access.mapper.AccessTenantManagementMapper;
import com.kujie.access.service.IPolicySubmitInformationService;
import com.kujie.access.utils.ConvertUtil;
import com.kujie.common.core.domain.R;
import com.kujie.common.core.utils.StringUtils;
import com.kujie.common.excel.utils.ExcelUtil;
import com.kujie.common.mybatis.core.page.PageQuery;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 政策申报 impl
 *
 * @author check
 * @date 2025-07-03
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PolicySubmitInformationServiceImpl implements IPolicySubmitInformationService {
    private final AccessTenantManagementMapper accessTenantManagementMapper;
    private final AccessPolicySubmitInformationMapper accessPolicySubmitInformationMapper;

    @Override
    public Page<PolicySubmitInformationVO> list(PolicySubmitInformationQuery policySubmitInformationQuery, PageQuery pageQuery) {
        var result = pageQuery.build(new PolicySubmitInformationVO());

        // 根据企业法人、企业名称查询企业信息
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(policySubmitInformationQuery.getCompanyName()), AccessTenantManagement::getCompanyName, policySubmitInformationQuery.getCompanyName());
        accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(policySubmitInformationQuery.getLegalPersonName()), AccessTenantManagement::getCompanyLegelPerson, policySubmitInformationQuery.getLegalPersonName());
        var accessTenantManagements = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper);

        // companyUuid -> AccessTenantManagement
        var idToCompany = accessTenantManagements.stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyUuid, Function.identity()));
        Set<String> companyUuids = idToCompany.keySet();

        // 构造政策审批查询条件
        var accessPolicySubmitInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessPolicySubmitInformation>();
        buildQueryWrapper(policySubmitInformationQuery, accessPolicySubmitInformationLambdaQueryWrapper, companyUuids);
        List<AccessPolicySubmitInformation> accessPolicySubmitInformationList = accessPolicySubmitInformationMapper.selectList(accessPolicySubmitInformationLambdaQueryWrapper);

        // 是否为高企
        if (policySubmitInformationQuery.getIsHighLevel() != null && policySubmitInformationQuery.getIsHighLevel() == 1) {
            accessPolicySubmitInformationList = accessPolicySubmitInformationList.stream().filter(accessPolicySubmitInformation -> {
                return StringUtils.isNotEmpty(accessPolicySubmitInformation.getHighLevelIdentificationNumber());
            }).toList();
        } else if (policySubmitInformationQuery.getIsHighLevel() != null && policySubmitInformationQuery.getIsHighLevel() == 0) {
            accessPolicySubmitInformationList = accessPolicySubmitInformationList.stream().filter(accessPolicySubmitInformation -> {
                return StringUtils.isEmpty(accessPolicySubmitInformation.getHighLevelIdentificationNumber());
            }).toList();
        }

        // 构造返回参数
        var accessPolicySubmitInformationVOS = accessPolicySubmitInformationList.stream().map(accessPolicySubmitInformation -> {
            var accessTenantManagement = idToCompany.get(accessPolicySubmitInformation.getCompanyUuid());
            return new PolicySubmitInformationVO(accessPolicySubmitInformation, accessTenantManagement);
        }).toList();

        List<PolicySubmitInformationVO> pagedList = accessPolicySubmitInformationVOS.stream()
            .skip((pageQuery.getPageNum() - 1) * pageQuery.getPageSize())
            .limit(pageQuery.getPageSize())
            .toList();

        result.setRecords(pagedList);
        result.setTotal(accessPolicySubmitInformationVOS.size());
        return result;
    }

    private static void buildQueryWrapper(PolicySubmitInformationQuery policySubmitInformationQuery, LambdaQueryWrapper<AccessPolicySubmitInformation> accessPolicySubmitInformationLambdaQueryWrapper, Set<String> companyUuids) {
        accessPolicySubmitInformationLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyUuids), AccessPolicySubmitInformation::getCompanyUuid, companyUuids);

        // 判断是否为规上企业
        accessPolicySubmitInformationLambdaQueryWrapper.eq(!(Objects.isNull(policySubmitInformationQuery.getIsStatistics())), AccessPolicySubmitInformation::getIsStatistics, policySubmitInformationQuery.getIsStatistics());

        // 是否签订招商协议
        accessPolicySubmitInformationLambdaQueryWrapper.eq(!(Objects.isNull(policySubmitInformationQuery.getIsSigned())), AccessPolicySubmitInformation::getIsSigned, policySubmitInformationQuery.getIsSigned());

        // 是否为中小企业
        accessPolicySubmitInformationLambdaQueryWrapper.eq(!(Objects.isNull(policySubmitInformationQuery.getIsMediumOrSmall())), AccessPolicySubmitInformation::getIsMediumOrSmall, policySubmitInformationQuery.getIsMediumOrSmall());

        // 知识产权数量
        accessPolicySubmitInformationLambdaQueryWrapper.le(StringUtils.isNotEmpty(policySubmitInformationQuery.getMinIntellectualCount()), AccessPolicySubmitInformation::getIntellectualCount, policySubmitInformationQuery.getMinIntellectualCount());
        accessPolicySubmitInformationLambdaQueryWrapper.ge(StringUtils.isNotEmpty(policySubmitInformationQuery.getMaxIntellectualCount()), AccessPolicySubmitInformation::getIntellectualCount, policySubmitInformationQuery.getMaxIntellectualCount());

        // 法人年龄
        accessPolicySubmitInformationLambdaQueryWrapper.le(StringUtils.isNotEmpty(policySubmitInformationQuery.getMinLegalAge()), AccessPolicySubmitInformation::getLegalAge, policySubmitInformationQuery.getMinLegalAge());
        accessPolicySubmitInformationLambdaQueryWrapper.ge(StringUtils.isNotEmpty(policySubmitInformationQuery.getMaxLegalAge()), AccessPolicySubmitInformation::getLegalAge, policySubmitInformationQuery.getMaxLegalAge());

        // 法人学历
        accessPolicySubmitInformationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(policySubmitInformationQuery.getLegalDegree()), AccessPolicySubmitInformation::getLegalDegree, policySubmitInformationQuery.getLegalDegree());
    }

    @Override
    public R<PolicySubmitInformationVO> detail(String companyUUID) {
        // 查询申报信息
        var accessPolicySubmitInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessPolicySubmitInformation>();
        accessPolicySubmitInformationLambdaQueryWrapper.eq(AccessPolicySubmitInformation::getCompanyUuid, companyUUID);
        var accessPolicySubmitInformation = accessPolicySubmitInformationMapper.selectOne(accessPolicySubmitInformationLambdaQueryWrapper);

        // 查询企业信息
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.eq(AccessTenantManagement::getCompanyUuid, companyUUID);
        var accessTenantManagement = accessTenantManagementMapper.selectOne(accessTenantManagementLambdaQueryWrapper);

        // 构造响应参数
        return R.ok(new PolicySubmitInformationVO(accessPolicySubmitInformation, accessTenantManagement));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertOrUpdate(PolicySubmitInformationVO policySubmitInformationVO) {
        int i = 0;

        if (StringUtils.isEmpty(policySubmitInformationVO.getCompanyUUID())) {
            String uuid = IdUtil.randomUUID();
            policySubmitInformationVO.setCompanyUUID(uuid);
        }

        var accessTenantManagement = buildAccessTenantManagement(policySubmitInformationVO);
        var accessPolicySubmitInformation = buildAccessPolicySubmitInformation(policySubmitInformationVO);

        // 查询是否已经存在相同的 company_uuid
        LambdaQueryWrapper<AccessTenantManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AccessTenantManagement::getCompanyUuid, accessTenantManagement.getCompanyUuid()).or().eq(AccessTenantManagement::getCompanyName, accessTenantManagement.getCompanyName());
        AccessTenantManagement tenantExisting = accessTenantManagementMapper.selectOne(queryWrapper);
        if (tenantExisting != null) {
            i = i + accessTenantManagementMapper.update(accessTenantManagement, queryWrapper);
        } else {
            i = i + accessTenantManagementMapper.insert(accessTenantManagement);
        }

        // 查询是否已经存在相同的 company_uuid
        LambdaQueryWrapper<AccessPolicySubmitInformation> accessPolicySubmitInformationLambdaQueryWrapper = new LambdaQueryWrapper<>();
        accessPolicySubmitInformationLambdaQueryWrapper.eq(AccessPolicySubmitInformation::getCompanyUuid, accessPolicySubmitInformation.getCompanyUuid());
        AccessPolicySubmitInformation policyExist = accessPolicySubmitInformationMapper.selectOne(accessPolicySubmitInformationLambdaQueryWrapper);
        if (policyExist != null) {
            i = i + accessPolicySubmitInformationMapper.update(accessPolicySubmitInformation, accessPolicySubmitInformationLambdaQueryWrapper);
        } else {
            i = i + accessPolicySubmitInformationMapper.insert(accessPolicySubmitInformation);
        }

        return i;
    }

    @Override
    public int batchDelete(List<String> ids) {
        var accessPolicySubmitInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessPolicySubmitInformation>();
        accessPolicySubmitInformationLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(ids), AccessPolicySubmitInformation::getCompanyUuid, ids);
        return accessPolicySubmitInformationMapper.delete(accessPolicySubmitInformationLambdaQueryWrapper);
    }

    @Override
    public List<PolicySubmitInformationExportImportVO> batchExport(PolicySubmitInformationQuery policySubmitInformationQuery, HttpServletResponse response) {
        // 构建查询企业信息wrapper
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        List<AccessPolicySubmitInformation> accessPolicySubmitInformationList;

        // 判断是否是全量导出
        if (!policySubmitInformationQuery.getIsAll()) {
            accessPolicySubmitInformationList = accessPolicySubmitInformationMapper.selectByIds(policySubmitInformationQuery.getIds());
        } else {
            // 构建企业信息查询条件
            accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(policySubmitInformationQuery.getCompanyName()), AccessTenantManagement::getCompanyName, policySubmitInformationQuery.getCompanyName());
            accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(policySubmitInformationQuery.getLegalPersonName()), AccessTenantManagement::getCompanyLegelPerson, policySubmitInformationQuery.getLegalPersonName());

            // 政策申报查询
            var accessPolicySubmitInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessPolicySubmitInformation>();
            accessPolicySubmitInformationList = accessPolicySubmitInformationMapper.selectList(accessPolicySubmitInformationLambdaQueryWrapper);
        }

        var companyUUIDs = accessPolicySubmitInformationList.stream().map(AccessPolicySubmitInformation::getCompanyUuid).toList();

        // 补全企业信息wrapper条件
        accessTenantManagementLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyUUIDs), AccessTenantManagement::getCompanyUuid, companyUUIDs);
        var companyUuidToInformation = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper).stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyUuid, Function.identity()));
        return accessPolicySubmitInformationList.stream().map(e -> new PolicySubmitInformationExportImportVO(e, companyUuidToInformation.get(e.getCompanyUuid()))).toList();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchImport(MultipartFile file) throws IOException {
        var accessPolicySubmitInformationList = new ArrayList<AccessPolicySubmitInformation>();
        var accessTenantManagements = new ArrayList<AccessTenantManagement>();

        // 提取EXCEL的数据
        var policySubmitInformationExportImportVOS = ExcelUtil.importExcel(file.getInputStream(), PolicySubmitInformationExportImportVO.class);
        if (CollectionUtils.isEmpty(policySubmitInformationExportImportVOS)) {
            log.info("数据为空");
            return 0;
        }

        // 获取企业信息
        List<String> companyNames = policySubmitInformationExportImportVOS.stream().map(PolicySubmitInformationExportImportVO::getCompanyName).toList();
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyNames), AccessTenantManagement::getCompanyName, companyNames);

        List<AccessTenantManagement> accessTenantManagementList = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper);
        var nameToAccessTenant = accessTenantManagementList.stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyName, Function.identity()));

        // 企业uuid是否已经存在在表中
        List<String> companyList = accessTenantManagementList.stream().map(AccessTenantManagement::getCompanyUuid).toList();
        var companyUuidToPolicy = accessPolicySubmitInformationMapper.selectList(new LambdaQueryWrapper<AccessPolicySubmitInformation>()
            .in(CollectionUtil.isNotEmpty(companyList), AccessPolicySubmitInformation::getCompanyUuid, companyList)).stream().collect(Collectors.toMap(AccessPolicySubmitInformation::getCompanyUuid, Function.identity()));

        // 获取更新、新增数据
        for (PolicySubmitInformationExportImportVO policySubmitInformationExportImportVO : policySubmitInformationExportImportVOS) {
            // 构造对象
            AccessTenantManagement accessTenantManagement = new AccessTenantManagement();
            AccessPolicySubmitInformation accessPolicySubmitInformation = new AccessPolicySubmitInformation();

            // 设置UUID
            setUUID(policySubmitInformationExportImportVO, nameToAccessTenant, accessTenantManagement, accessPolicySubmitInformation);

            // 设置企业信息参数
            setAccessTenantManagement(policySubmitInformationExportImportVO, accessTenantManagement, nameToAccessTenant);

            // 政策申报参数
            setAccessPolicySubmitInformation(policySubmitInformationExportImportVO, accessPolicySubmitInformation, companyUuidToPolicy);

            accessPolicySubmitInformationList.add(accessPolicySubmitInformation);
            accessTenantManagements.add(accessTenantManagement);
        }

        List<BatchResult> tenantResults = accessTenantManagementMapper.insertOrUpdate(accessTenantManagements);
        List<BatchResult> submitResults = accessPolicySubmitInformationMapper.insertOrUpdate(accessPolicySubmitInformationList);
        return tenantResults.size() + submitResults.size();
    }

    private void setAccessPolicySubmitInformation(PolicySubmitInformationExportImportVO policySubmitInformationExportImportVO, AccessPolicySubmitInformation accessPolicySubmitInformation, Map<String, AccessPolicySubmitInformation> companyUuidToPolicy) {
        if (companyUuidToPolicy.containsKey(accessPolicySubmitInformation.getCompanyUuid())) {
            accessPolicySubmitInformation.setId(companyUuidToPolicy.get(accessPolicySubmitInformation.getCompanyUuid()).getId());
        }
        accessPolicySubmitInformation.setIsSigned(ConvertUtil.getCheckIf(policySubmitInformationExportImportVO.getIsSigned()));
        accessPolicySubmitInformation.setSignDate(policySubmitInformationExportImportVO.getSignDate());
        accessPolicySubmitInformation.setFirstYearSubsidyPeriod(policySubmitInformationExportImportVO.getFirstYearSubsidyPeriod());
        accessPolicySubmitInformation.setSecondYearSubsidyPeriod(policySubmitInformationExportImportVO.getSecondYearSubsidyPeriod());
        accessPolicySubmitInformation.setThirdYearSubsidyPeriod(policySubmitInformationExportImportVO.getThirdYearSubsidyPeriod());
        accessPolicySubmitInformation.setHighLevelIdentificationNumber(policySubmitInformationExportImportVO.getHighLevelIdentificationNumber());
        accessPolicySubmitInformation.setIsStatistics(ConvertUtil.getCheckIf(policySubmitInformationExportImportVO.getIsStatistics()));
        accessPolicySubmitInformation.setTechnosphere(policySubmitInformationExportImportVO.getTechnosphere());
        accessPolicySubmitInformation.setDistrictsAndCounties(policySubmitInformationExportImportVO.getDistrictsAndCounties());
        accessPolicySubmitInformation.setGarden(policySubmitInformationExportImportVO.getGarden());
        accessPolicySubmitInformation.setTheAffiliatedStreet(policySubmitInformationExportImportVO.getTheAffiliatedStreet());
        accessPolicySubmitInformation.setIntellectualCount(policySubmitInformationExportImportVO.getIntellectualCount());
        accessPolicySubmitInformation.setIsMediumOrSmall(ConvertUtil.getCheckIf(policySubmitInformationExportImportVO.getIsMediumOrSmall()));
        accessPolicySubmitInformation.setNumberOfInsuredIndividuals(policySubmitInformationExportImportVO.getNumberOfInsuredIndividuals());
        accessPolicySubmitInformation.setRevenueIn2024(policySubmitInformationExportImportVO.getRevenueIn2024());
        accessPolicySubmitInformation.setTaxationIn2024(policySubmitInformationExportImportVO.getTaxationIn2024());
        accessPolicySubmitInformation.setIsJoinTheIncubator(ConvertUtil.getCheckIf(policySubmitInformationExportImportVO.getIsJoinTheIncubator()));
        accessPolicySubmitInformation.setNeedToLinkTheEnterpriseType(policySubmitInformationExportImportVO.getNeedToLinkTheEnterpriseType());
        accessPolicySubmitInformation.setLegalGender(ConvertUtil.getGender(policySubmitInformationExportImportVO.getLegalGender()));
        accessPolicySubmitInformation.setLegalAge(policySubmitInformationExportImportVO.getLegalAge());
        accessPolicySubmitInformation.setLegalDegree(policySubmitInformationExportImportVO.getLegalDegree());
        accessPolicySubmitInformation.setShareholdingRatioOfLegalEntities(policySubmitInformationExportImportVO.getShareholdingRatioOfLegalEntities());
        accessPolicySubmitInformation.setRemark(policySubmitInformationExportImportVO.getRemark());
    }

    private static void setAccessTenantManagement(PolicySubmitInformationExportImportVO policySubmitInformationExportImportVO, AccessTenantManagement accessTenantManagement, Map<String, AccessTenantManagement> nameToAccessTenantManagementMap) {
        if (nameToAccessTenantManagementMap.containsKey(policySubmitInformationExportImportVO.getCompanyName())) {
            accessTenantManagement.setId(nameToAccessTenantManagementMap.get(policySubmitInformationExportImportVO.getCompanyName()).getId());
        }
        accessTenantManagement.setMainBusiness(policySubmitInformationExportImportVO.getMainBusiness());
        accessTenantManagement.setUnifiedSocialCreditIdentifier(policySubmitInformationExportImportVO.getUnifiedSocialCreditIdentifier());
        accessTenantManagement.setLegelPersonPhone(policySubmitInformationExportImportVO.getLegelPersonPhone());
        accessTenantManagement.setEstablishedTime(policySubmitInformationExportImportVO.getEstablishedTime());
        accessTenantManagement.setCompanyName(policySubmitInformationExportImportVO.getCompanyName());
        accessTenantManagement.setCompanyLegelPerson(policySubmitInformationExportImportVO.getCompanyLegelPerson());
        accessTenantManagement.setAdministrativeContactPerson(policySubmitInformationExportImportVO.getAdministrativeContactPerson());
        accessTenantManagement.setAdministrativeContactPersonPhone(policySubmitInformationExportImportVO.getAdministrativeContactPersonPhone());
        accessTenantManagement.setBusinessRegistrationAddress(policySubmitInformationExportImportVO.getBusinessRegistrationAddress());
        accessTenantManagement.setActualOfficeAddress(policySubmitInformationExportImportVO.getActualOfficeAddress());
    }

    private static void setUUID(PolicySubmitInformationExportImportVO policySubmitInformationExportImportVO, Map<String, AccessTenantManagement> nameToUUID, AccessTenantManagement accessTenantManagement, AccessPolicySubmitInformation accessPolicySubmitInformation) {
        if (nameToUUID.containsKey(policySubmitInformationExportImportVO.getCompanyName())) {
            accessTenantManagement.setId(nameToUUID.get(policySubmitInformationExportImportVO.getCompanyName()).getId());
            accessTenantManagement.setCompanyUuid(nameToUUID.get(policySubmitInformationExportImportVO.getCompanyName()).getCompanyUuid());
            accessPolicySubmitInformation.setCompanyUuid(nameToUUID.get(policySubmitInformationExportImportVO.getCompanyName()).getCompanyUuid());
        } else {
            String uuid = IdUtil.randomUUID();
            accessTenantManagement.setCompanyUuid(uuid);
            accessPolicySubmitInformation.setCompanyUuid(uuid);
        }
    }

    private static AccessPolicySubmitInformation buildAccessPolicySubmitInformation(PolicySubmitInformationVO policySubmitInformationVO) {
        var accessPolicySubmitInformation = new AccessPolicySubmitInformation();
        accessPolicySubmitInformation.setCompanyUuid(policySubmitInformationVO.getCompanyUUID());
        accessPolicySubmitInformation.setIsSigned(policySubmitInformationVO.getIsSigned());
        accessPolicySubmitInformation.setSignDate(policySubmitInformationVO.getSignDate());
        accessPolicySubmitInformation.setFirstYearSubsidyPeriod(policySubmitInformationVO.getFirstYearSubsidyPeriod());
        accessPolicySubmitInformation.setSecondYearSubsidyPeriod(policySubmitInformationVO.getSecondYearSubsidyPeriod());
        accessPolicySubmitInformation.setThirdYearSubsidyPeriod(policySubmitInformationVO.getThirdYearSubsidyPeriod());
        accessPolicySubmitInformation.setHighLevelIdentificationNumber(policySubmitInformationVO.getHighLevelIdentificationNumber());
        accessPolicySubmitInformation.setIsStatistics(policySubmitInformationVO.getIsStatistics());
        accessPolicySubmitInformation.setTechnosphere(policySubmitInformationVO.getTechnosphere());
        accessPolicySubmitInformation.setDistrictsAndCounties(policySubmitInformationVO.getDistrictsAndCounties());
        accessPolicySubmitInformation.setGarden(policySubmitInformationVO.getGarden());
        accessPolicySubmitInformation.setTheAffiliatedStreet(policySubmitInformationVO.getTheAffiliatedStreet());
        accessPolicySubmitInformation.setIntellectualCount(policySubmitInformationVO.getIntellectualCount());
        accessPolicySubmitInformation.setIsMediumOrSmall(policySubmitInformationVO.getIsMediumOrSmall());
        accessPolicySubmitInformation.setNumberOfInsuredIndividuals(policySubmitInformationVO.getNumberOfInsuredIndividuals());
        accessPolicySubmitInformation.setRevenueIn2024(policySubmitInformationVO.getRevenueIn2024());
        accessPolicySubmitInformation.setTaxationIn2024(policySubmitInformationVO.getTaxationIn2024());
        accessPolicySubmitInformation.setIsJoinTheIncubator(policySubmitInformationVO.getIsJoinTheIncubator());
        accessPolicySubmitInformation.setNeedToLinkTheEnterpriseType(policySubmitInformationVO.getNeedToLinkTheEnterpriseType());
        accessPolicySubmitInformation.setLegalGender(policySubmitInformationVO.getLegalGender());
        accessPolicySubmitInformation.setLegalAge(policySubmitInformationVO.getLegalAge());
        accessPolicySubmitInformation.setLegalDegree(policySubmitInformationVO.getLegalDegree());
        accessPolicySubmitInformation.setShareholdingRatioOfLegalEntities(policySubmitInformationVO.getShareholdingRatioOfLegalEntities());
        accessPolicySubmitInformation.setRemark(policySubmitInformationVO.getRemark());
        return accessPolicySubmitInformation;
    }

    private static AccessTenantManagement buildAccessTenantManagement(PolicySubmitInformationVO policySubmitInformationVO) {
        var accessTenantManagement = new AccessTenantManagement();
        accessTenantManagement.setCompanyUuid(policySubmitInformationVO.getCompanyUUID());
        accessTenantManagement.setCompanyName(policySubmitInformationVO.getCompanyName());
        accessTenantManagement.setUnifiedSocialCreditIdentifier(policySubmitInformationVO.getUnifiedSocialCreditIdentifier());
        accessTenantManagement.setMainBusiness(policySubmitInformationVO.getMainBusiness());
        accessTenantManagement.setEstablishedTime(policySubmitInformationVO.getEstablishedTime());
        accessTenantManagement.setCompanyLegelPerson(policySubmitInformationVO.getCompanyLegelPerson());
        accessTenantManagement.setLegelPersonPhone(policySubmitInformationVO.getLegelPersonPhone());
        accessTenantManagement.setAdministrativeContactPerson(policySubmitInformationVO.getAdministrativeContactPerson());
        accessTenantManagement.setAdministrativeContactPersonPhone(policySubmitInformationVO.getAdministrativeContactPersonPhone());
        accessTenantManagement.setBusinessRegistrationAddress(policySubmitInformationVO.getBusinessRegistrationAddress());
        accessTenantManagement.setActualOfficeAddress(policySubmitInformationVO.getActualOfficeAddress());
        return accessTenantManagement;
    }
}
